/**********************************************************************************
Copyright (C), by AppleCai
Project                      : Study Kernel driver
Description                  : User Application for cdev
History                      :
CPU and Compiler             : AM335x,GCC
GenDate                      : 2020-10-30
OwnerBy                      : Apple Cai
**********************************************************************************/
#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"
#include "poll.h"
#include "sys/select.h"
#include "sys/time.h"
#include "linux/ioctl.h"
#include "applepaper_cmd.h"
int main(int argc, char *argv[])
{
	int fd;
	int ret = 0;
	char *filename;
	unsigned char data;

	if (argc != 2) {
		printf("Error Usage!\r\n");
		return -1;
	}

	filename = argv[1];
	//fd = open(filename, O_RDWR | O_NONBLOCK);
	fd = open(filename, O_RDWR);
	if (fd < 0) {
		printf("Can't open file %s\r\n", filename);
		return -1;
	}
	else
	{
		if(ioctl(fd, APPLEPAPER_CLEAR, 0)<0)
			printf("clear file %s failed!\r\n",filename);
		while(1)
		{


			/* read each one */
			ret = read(fd, &data, 1);
			if(ret ==1)
			{
				//printf("%c",data);
			}
			else if(ret < 0){
				printf("read file %s failed!\r\n", filename);
			}
			else
			{}


		}

		/* close */
		ret = close(fd);
		if(ret < 0){
			printf("Can't close file %s\r\n", filename);
			return -1;
		}
	}
	return 0;

}
